package ihm;

import java.awt.EventQueue;
import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.sql.Date;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;
import javax.swing.border.EmptyBorder;

import metier.Spectacle;

public class Ajout_Spectacle extends JFrame implements ActionListener  
{

	private JPanel contentPane;
	private JTextField txtNomSpectacle;
	private JTextField txtDateSpectacle;
	private JTextField txtTatifSpectacle;
	private JLabel lblNomDuSpectacle;
	private JLabel lblDateSpectacle;
	private JLabel lblTarifSpectacle;
	private JButton btnValider;
	private JButton btnAnnuler;
	private JLabel lblNouveauSpectacle;
	private JLabel lblCodeDuSpectacle;
	private JTextField txtCodeSpectacle;

	/**
	 * Launch the application.
	 */
	public static void main(String[] args) 
	{
		EventQueue.invokeLater(new Runnable() 
		{
			public void run() 
			{
				try 
				{
					Ajout_Spectacle frame = new Ajout_Spectacle();
					frame.setVisible(true);
				} catch (Exception e) 
				{
					e.printStackTrace();
				}
			}
		});
	}

	/**
	 * Create the frame.
	 */
	public Ajout_Spectacle() 
	{
		setTitle("Ajout d'un spectacle");
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setBounds(100, 100, 450, 300);
		contentPane = new JPanel();
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		setContentPane(contentPane);
		contentPane.setLayout(null);
		
		txtNomSpectacle = new JTextField();
		txtNomSpectacle.setBounds(181, 93, 86, 20);
		contentPane.add(txtNomSpectacle);
		txtNomSpectacle.setColumns(10);
		
		txtDateSpectacle = new JTextField();
		txtDateSpectacle.setBounds(181, 127, 86, 20);
		contentPane.add(txtDateSpectacle);
		txtDateSpectacle.setColumns(10);
		
		txtTatifSpectacle = new JTextField();
		txtTatifSpectacle.setBounds(181, 158, 86, 20);
		contentPane.add(txtTatifSpectacle);
		txtTatifSpectacle.setColumns(10);
		
		lblNomDuSpectacle = new JLabel("Nom du spectacle :");
		lblNomDuSpectacle.setBounds(50, 96, 100, 14);
		contentPane.add(lblNomDuSpectacle);
		
		lblDateSpectacle = new JLabel("Date du spectacle :");
		lblDateSpectacle.setBounds(50, 130, 100, 14);
		contentPane.add(lblDateSpectacle);
		
		lblTarifSpectacle = new JLabel("Tarif du spectacle :");
		lblTarifSpectacle.setBounds(50, 161, 100, 14);
		contentPane.add(lblTarifSpectacle);
		
		btnValider = new JButton("Valider");
		btnValider.addActionListener(this);
		btnValider.setBounds(187, 205, 91, 23);
		contentPane.add(btnValider);
		
		btnAnnuler = new JButton("Annuler");
		btnAnnuler.addActionListener(this);
		btnAnnuler.setBounds(312, 205, 91, 23);
		contentPane.add(btnAnnuler);
		
		lblNouveauSpectacle = new JLabel("Nouveau Spectacle");
		lblNouveauSpectacle.setFont(new Font("Times New Roman", Font.BOLD | Font.ITALIC, 14));
		lblNouveauSpectacle.setBounds(168, 11, 132, 33);
		contentPane.add(lblNouveauSpectacle);
		
		lblCodeDuSpectacle = new JLabel("Code du spectacle :");
		lblCodeDuSpectacle.setBounds(50, 58, 100, 14);
		contentPane.add(lblCodeDuSpectacle);
		
		txtCodeSpectacle = new JTextField();
		txtCodeSpectacle.setBounds(181, 55, 86, 20);
		contentPane.add(txtCodeSpectacle);
		txtCodeSpectacle.setColumns(10);
	}
	
	public void actionPerformed(ActionEvent e) 
	{
		if (e.getSource() == btnAnnuler)
		{
			dispose();
		}
		
		if (e.getSource() == btnValider)
		{
			Spectacle unSpectacle;
			unSpectacle = new Spectacle(Integer.parseInt(txtCodeSpectacle.getText()),txtNomSpectacle.getText(), txtDateSpectacle.getText(), Double.parseDouble(txtTatifSpectacle.getText()));	
		}
	}
}
	
